package com.bignerdranch.android.ecar.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bignerdranch.android.ecar.Bean.FaultResultBean;
import com.bignerdranch.android.ecar.R;

import java.util.List;


/**
 * Created by Administrator on 2016/7/20.
 */
public class FaultResultAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<FaultResultBean> mData;

    public FaultResultAdapter(Context context, List<FaultResultBean> data) {
        mContext = context;
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView== null){
            convertView = mInflater.inflate(R.layout.fault_result_item ,null);
        }
        ViewHold hold = new ViewHold();
        if (convertView.getTag()==null){
            hold.time = (TextView) convertView.findViewById(R.id.time);
            hold.place = (TextView) convertView.findViewById(R.id.place);
            hold.action = (TextView) convertView.findViewById(R.id.action);
            hold.decide = (TextView) convertView.findViewById(R.id.decide);
            hold.money_status = (TextView) convertView.findViewById(R.id.money_status);
            hold.money = (TextView) convertView.findViewById(R.id.money);
            hold.point = (TextView) convertView.findViewById(R.id.point);

            convertView.setTag(hold);
        }else {
            hold = (ViewHold) convertView.getTag();
        }

        hold.time.setText(mData.get(position).getTime());
        hold.place.setText(mData.get(position).getPlace());
        hold.action.setText(mData.get(position).getAction());
        hold.decide.setText(mData.get(position).getDecide());
        hold.money_status.setText(mData.get(position).getMoney_status());
        hold.money.setText(mData.get(position).getMoney());
        hold.point.setText(mData.get(position).getPoint());


        return convertView;
    }

    private static class ViewHold{
        private TextView time;
        private TextView place;
        private TextView action;
        private TextView decide;
        private TextView money_status;
        private TextView money;
        private TextView point;
    }
}
